package com.lhnstart.learn.bases.onedimensional;

import java.util.Scanner;

/**
 * 数据添加
 *
 * @author lhn
 * @date 2022/10/30 18:43
 * @since 1.0.0
 **/
public class ArrayAdd {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] array = {11, 22, 33, 44, 55};
        do {
            System.out.println("输入你要保存的数据");
            int nextInt = scanner.nextInt();
            int[] newArray = new int[array.length + 1];

            for (int j = 0; j < array.length; j++) {
                newArray[j] = array[j];
            }
            newArray[array.length] = nextInt;
            array = newArray;

            System.out.print("添加后的数组是：");
            for (int j : array) {
                System.out.print(j + "  ");
            }
            System.out.println("继续保存：Y ，退出 N");
            char charAt = scanner.next().charAt(0);
            if (charAt == 'N') {
                System.out.println("退出输入！！！");
                break;
            }
        } while (true);
    }

}